package com.guodi.model.controller;


import com.alibaba.fastjson.JSON;
import com.guodi.common.constant.StatusCode;
import com.guodi.common.utils.AjaxResult;
import com.guodi.core.boot.ctrl.BaseController;
import com.guodi.model.service.IIdtValueExportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @描述: 指标数值导出文档 控制类
 * @作者: 陈宏成
 * @日期: 2021/1/14 15:26
 **/
@RestController
@RequestMapping("/IdtValueExport")
@Api(value = "API - IdtValueExportController", description = "指标数值导出",tags = "指标数值导出控制类")
public class IdtValueExportController  extends BaseController {

    @Resource
    private IIdtValueExportService iIdtValueExportService;


    /**
     * @描述: （指标填报--体检评估指标模块）导出【体检评估_导出报告.xls】
     * @入参:
     * @出参:
     * @作者: 陈宏成
     * @日期: 2021/02/02
     **/
    @PostMapping("/exportAssessmentExcel")
    @ApiOperation(value = "导出【体检评估_导出报告.xls】")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "idtTypeCode", value = "指标体系编码", required = true, dataType = "string",paramType = "query", example = "current-evaluate"),
            @ApiImplicitParam(name = "divisionCode", value = "行政区划代码",required = true, dataType = "string", paramType = "query",example = "441203"),
            @ApiImplicitParam(name = "idtType", value = "指标类型", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "keyWord", value = "关键字", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "idtStatus", value = "指标状态", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startYear", value = "开始年份", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "endYear", value = "结束年份", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "idtTypeId", value = "指标体系ID", required = true, dataType = "string", paramType = "query")
    })
    public void exportAssessmentExcel (HttpServletResponse response, String idtTypeCode, String divisionCode, String idtType, String keyWord,
                                       String idtStatus, String startYear, String endYear, String idtTypeId){
        String deptId = this.getUser().getDeptId();
        iIdtValueExportService.exportAssessmentExcel(response,idtTypeCode,divisionCode,deptId,idtType,keyWord,idtStatus,startYear,endYear, idtTypeId);
    }

    /**
     * @描述: 导出【指标监测值】Excel
     * @作者: 陈宏成
     * @日期: 2021/01/21
     **/
    @PostMapping("/exportMonitorValueExcel")
    @ApiOperation(value = "导出【指标监测值】Excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "指标体系编码", required = true, dataType = "string", paramType = "query",example = "city-county-plan"),
            @ApiImplicitParam(name = "divisionCode", value = "区域编码",  required = true,dataType = "string", paramType = "query",example = "3201"),
            @ApiImplicitParam(name = "year", value = "指标数值年份", required = true,dataType = "string", paramType = "query",example = "2019"),
            @ApiImplicitParam(name = "orgId", value = "机构id", required = true, dataType = "string", paramType = "query",example = "65fc1451aa4640c795b971ae9199456c"),
            @ApiImplicitParam(name = "particularYear", value = "指标体系年份", required = true, dataType = "string", paramType = "query")
    })
    public void exportMonitorValueExcel(HttpServletResponse response, String code, String divisionCode, Integer year, String orgId, String particularYear){
        iIdtValueExportService.exportMonitorValueExcel(response, code, divisionCode, year, orgId, particularYear);
    }

    /**
     * @描述: 导出【指标规划值】Excel
     * @作者: 汤厚韬
     * @日期: 2021/01/22
     **/
    @PostMapping("/exportTargetValueExcel")
    @ApiOperation(value = "导出【指标规划值】Excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "指标体系编码", required = true, dataType = "string", paramType = "query",example = "city-county-plan"),
            @ApiImplicitParam(name = "divisionCode", value = "区域编码",  required = true,dataType = "string", paramType = "query",example = "3201"),
            @ApiImplicitParam(name = "year", value = "指标数值年份", required = true,dataType = "string", paramType = "query",example = "2019"),
            @ApiImplicitParam(name = "orgId", value = "机构id", required = true, dataType = "string", paramType = "query",example = "65fc1451aa4640c795b971ae9199456c"),
            @ApiImplicitParam(name = "particularYear", value = "指标体系年份", required = true, dataType = "string", paramType = "query")
    })
    public void exportTargetValueExcel(HttpServletResponse response, String code, String divisionCode, String year, String orgId, String particularYear){
        iIdtValueExportService.exportTargetValueExcel(response, code, divisionCode, year, orgId, particularYear);
    }

    /**
     * @描述: 导出【指标上报值】Excel
     * @作者: 汤厚韬
     * @日期: 2021/01/22
     **/
    @PostMapping("/exportReportValueExcel")
    @ApiOperation(value = "导出【指标上报值】Excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "指标体系编码", required = true, dataType = "string", paramType = "query",example = "city-county-plan"),
            @ApiImplicitParam(name = "divisionCode", value = "区域编码",  required = true,dataType = "string", paramType = "query",example = "3201"),
            @ApiImplicitParam(name = "year", value = "指标数值年份", required = true,dataType = "string", paramType = "query",example = "2019"),
            @ApiImplicitParam(name = "orgId", value = "机构id", required = true, dataType = "string", paramType = "query",example = "65fc1451aa4640c795b971ae9199456c"),
            @ApiImplicitParam(name = "particularYear", value = "指标体系年份", required = true, dataType = "string", paramType = "query")
    })
    public void exportReportValueExcel(HttpServletResponse response, String code, String divisionCode, String year, String orgId, String particularYear){
        iIdtValueExportService.exportReportValueExcel(response, code, divisionCode, year, orgId, particularYear);
    }

    /**
     * @描述: 导出【国土空间规划监测评估预警报告】word报告
     * @作者: 陈宏成
     * @日期: 2021/01/20
     **/
    @PostMapping("/exportMonitorWarningReport")
    @ApiOperation(value = "导出【国土空间规划监测评估预警报告】word报告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "indicatorsTypeCode", value = "指标体系编码", required = true, dataType = "string", paramType = "query",example = "city-county-plan"),
            @ApiImplicitParam(name = "divisionCode", value = "区域编码",  dataType = "string", paramType = "query",example = "3201"),
            @ApiImplicitParam(name = "year", value = "指标数值年份", dataType = "string", paramType = "query",example = "2019"),
            @ApiImplicitParam(name = "orgId", value = "机构id", required = true, dataType = "string", paramType = "query",example = "65fc1451aa4640c795b971ae9199456c"),
            @ApiImplicitParam(name = "particularYear", value = "指标体系年份", required = true, dataType = "string", paramType = "query")
    })
    public void exportMonitorWarningReport(HttpServletResponse response, String indicatorsTypeCode,  String divisionCode,Integer year,
                                           String orgId, String particularYear) throws IOException {
        try{
            iIdtValueExportService.exportMonitorWarningReport(response, indicatorsTypeCode, divisionCode, year, orgId, particularYear);
        }catch (Exception e){
            AjaxResult ajaxResult = new AjaxResult(StatusCode.ERROR_CODE_40005, "导出失败");
            response.setContentType("application/json;charset=UTF-8;");
            ServletOutputStream outputStream = response.getOutputStream();
            outputStream.write(JSON.toJSONString(ajaxResult).getBytes("UTF-8"));
            outputStream.flush();
            outputStream.close();
        }
    }

    /**
     * @描述: 导出【监测评估报告】word
     * @作者: 陈宏成
     * @日期: 2021/01/14
     **/
    @PostMapping("/exportMonitorValue")
    @ApiOperation(value = "导出【监测评估报告】word")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "指标体系编码", required = true, dataType = "string", paramType = "query",example = "city-county-plan"),
            @ApiImplicitParam(name = "divisionCode", value = "区域编码",  required = true,dataType = "string", paramType = "query",example = "3201"),
            @ApiImplicitParam(name = "year", value = "指标数值年份", required = true,dataType = "string", paramType = "query",example = "2019"),
            @ApiImplicitParam(name = "orgId", value = "机构id", required = true, dataType = "string", paramType = "query",example = "65fc1451aa4640c795b971ae9199456c"),
            @ApiImplicitParam(name = "particularYear", value = "指标体系年份", required = true, dataType = "string", paramType = "query")
    })
    public void exportMonitorValue(HttpServletResponse response, String code, String divisionCode, Integer year, String orgId, String particularYear) {
       iIdtValueExportService.exportMonitorValue(response, code, divisionCode, year, orgId, particularYear);
    }

}
